from django.test import TestCase
import sys
import os
import csv
import json

pwd = os.path.dirname(os.path.realpath(__file__))
sys.path.append(pwd + "../")

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "BasketballCommunity.settings")

import django

django.setup()

from users.models import UserProfile
from article.models import Article, Category, Race

user = UserProfile.objects.all()[0]

with open('data/NBASchedule.csv', 'r', encoding='utf-8', errors='ignore') as f:
    content = csv.reader(f)
    for con in content:
        race = Race()
        race.begin = con[0]
        race.end = con[0]
        race.team_a = con[2]
        race.team_b = con[3]
        race.point_a = int(con[4])
        race.point_b = int(con[5])
        type = con[1]
        if type == 'NBA季前赛':
            pk = 9
        elif type == 'NBA常规赛':
            pk = 10
        else:
            pk = 11

        category = Category.objects.get(pk=pk)
        race.race_category = category
        race.save()

